﻿using System;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using DigitalRune.Windows.TextEditor.Actions;

namespace Zove.Desktop {

    public partial class ConsoleWindow : DockContent, IDesktopView {

        private static ConsoleWindow window = new ConsoleWindow();

        public static ConsoleWindow Instance {
            get {
                return window;
            }
        }

        public ConsoleWindow() {
            InitializeComponent();

            this.MdiParent = DesktopFormContext.Context.Main;
            TextBoxWriter writer = new TextBoxWriter(this.tecOutput);
            Console.SetOut(writer);
        }

        public ConsoleWindow(string message)
        {
            InitializeComponent();

            this.MdiParent = DesktopFormContext.Context.Main;
            this.tecOutput.Text = message;
        }

        #region IDesktopForm Members

        public DigitalRune.Windows.TextEditor.TextEditorControl GetTextEditorControl() {
            return this.tecOutput;
        }

        public string GetFileName() {
            throw new NotImplementedException();
        }

        public string GetFileExtension() {
            throw new NotImplementedException();
        }

        public void Save(string fileName) {
            throw new NotImplementedException();
        }

        public string GetFileFilter() {
            throw new NotImplementedException();
        }

        public virtual string GetColourScheme() {
            return string.Empty;
        }

        #endregion

        private void cutToolStripMenuItem_Click(object sender, EventArgs e) {
            Cut copy = new Cut();
            this.Execute(copy);
        }

        private void Execute(AbstractEditAction action) {
            action.Execute(this.tecOutput);
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e) {
            Copy copy = new Copy();
            this.Execute(copy);
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e) {
            Paste copy = new Paste();
            this.Execute(copy);
        }
    }
}
